<template>
    <el-container class="home-container">
        <!--主页头部区域-->
        <el-header>
            <div>
                <img src="../assets/guigulogo.png" alt="" class="logo">
                <span>电商管理系统</span>
            </div>
            <el-button type="info" @click="logout"> 退出</el-button>
        </el-header>
        <el-container>
            <!--侧边栏菜单-->
        <el-aside :width="iscollapse ? '64px' :'200px'">
            <div class="toggle-button" @click="toggleCollapse">| | |</div>
            <el-menu
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409eff"
      :unique-opened="true"
      :collapse="iscollapse"
      :collapse-transition="false"
      router
      :default-active="activePath"
      >
      <!--一级菜单-->
      <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
        <!--一级菜单的模板区域-->
        <template slot="title">
            <!--图标-->
            <i :class="item.iamge_url"></i>
            <!--文本-->
            <span>{{item.name}}</span>
        </template>
       <!--二级菜单-->
          <el-menu-item :index="'/'+subItem.target" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState('/'+subItem.target)">
            <template slot="title">
            <!--图标-->
            <i :class="subItem.iamgeUrl"></i>
            <!--文本-->
            <span>{{subItem.name}}</span>
        </template>
        </el-menu-item>
        </el-submenu>
    </el-menu>
        </el-aside>
            <el-main>
                <router-view></router-view>
            </el-main>
         </el-container>
</el-container>
    

</template>

<script>
import router from '@/router';

export default{
    data(){
        return{
        imgUrl: '', 
        LogName:'',
        menuList: [],
        iscollapse: false,
        activePath:''
        }
        
    },
    created(){
        this.getMenuList()
    },
    methods:{
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login");
        },
        async getMenuList(){
            
            const staff=JSON.parse(sessionStorage.getItem('token'))
            const {data:res}=await this.$http.post( '/sysMenu/getmenu',staff)
            this.imgUrl=staff.headUrl
            this.LogName=staff.name
            this.menuList=res
            console.log(res)
            console.log(this.imgurl)
            console.log(this.LogName)
        },
        toggleCollapse(){
            this.iscollapse =  !this.iscollapse
        },
        saveNavState(activePath){
            window.sessionStorage.setItem('activePath',activePath)
            this.activePath=activePath
        }
    }
}
</script>
<style lang="less" scoped>
.el-header{
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0px;
    align-items: center;
    color: #EAEDF1;
    font-size: 20px;
    > div{
        display: flex;
        align-items: center;
        span{
            margin-left: 15px;
        }
    }
}
.el-aside{
    background-color: #333744;
    border-right: 0px;
}
.el-main{
    background-color: #EAEDF1;
}
.home-container{
    height: 100%;
}
.logo{
    height: 50px;
}
.toggle-button{
    background-color: #475163;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    cursor: pointer;
}
</style>